/***************************************************************************//**
 * @file FDM/FDM_Atmosphere.h
 * @author  Marek M. Cel <marekcel@mscsim.org>
 *
 * @section LICENSE
 *
 * Copyright (C) 2013 Marek M. Cel
 *
 * This file is part of MScSim. You can redistribute and modify it under
 * the terms of GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.
 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * Further information about the GNU General Public License can also be found
 * on the world wide web at http://www.gnu.org.
 ******************************************************************************/
#ifndef FDM_ATMOSPHERE_H
#define FDM_ATMOSPHERE_H

////////////////////////////////////////////////////////////////////////////////

/**
 * This class provides simplified model of US Standard Atmosphere 1976.
 * @see NASA-TM-X-74335 - US Standard Atmosphere 1976
 */
class FDM_Atmosphere
{
public:

    /** Constructor. */
    FDM_Atmosphere();

    /** Destructor. */
    virtual ~FDM_Atmosphere();

    /**
     * This function sets boundary conditions (sea level temperature and pressure)
     * due to temperature and pressure at given altitude.
     * @param tempK temperature at given altitude [K]
     * @param press pressure at given altitude [Pa]
     * @param alt altitude above mean sea level (no more that 11000 metres) [m]
     */
    void init( double tempK, double press, double alt = 0.0f );
    
    /**
     * This function computes air parameters at given altitude due to boundary
     * conditions.
     * @param alt altitude above mean sea level [m]
     */
    void update( double alt );

    inline double getTempK() const { return m_tempK; }
    inline double getTempC() const { return m_tempC; }
    inline double getPress() const { return m_press; }
    inline double getDens()  const { return m_dens;  }
    inline double getSoS()   const { return m_sos;   }
    inline double getVisc()  const { return m_visc;  }

private:

    static const double m_G;    ///< [m/s^2] gravity acceleration
    static const double m_R;    ///< [N*m/(kmol*K)] gas constant
    static const double m_S;    ///< [K] Sutherland constant
    static const double m_B;    ///< [kg/(s*m*K^0.5)] quantity constant in the expression for dynamic viscosity

    double m_tempK_0;   ///< [K] temperature at sea level
    double m_press_0;   ///< [Pa] pressure at sea level

    double m_tempRate;  ///< [K/m] temperature drop rate up to 11 000 metres

    double m_tempK;     ///< [K] temperature
    double m_tempC;     ///< [deg C] temperature
    double m_press;     ///< [Pa] pressure
    double m_dens;      ///< [kg/m^3] density
    double m_sos;       ///< [m/s] speed of sound
    double m_visc;      ///< [Pa*s] dynamic viscosity
};

////////////////////////////////////////////////////////////////////////////////

#endif // FDM_ATMOSPHERE_H
